package com.eastedu.enums;


import com.eastedu.entity.CommonTreeEntity;

/**
 * 添加节点的操作类型
 *
 * @author luozhenzhong
 */
public enum NodeAppendOperation {
    /**
     * 追加同级节点
     */
    APPEND_BROTHER() {
        @Override
        <P extends CommonTreeEntity> Long dedicate(P currentNode) {
            return currentNode.getParentId();
        }


        @Override
        public <P extends CommonTreeEntity> void init(Long userId, P currentNode, P node) {
            node.setParentId(currentNode.getParentId());
            node.setLevel(currentNode.getLevel());
            node.setOrder(currentNode.getOrder());
        }


    },
    /**
     * 追加子级节点
     */
    APPEND_CHILD() {
        @Override
        <P extends CommonTreeEntity> Long dedicate(P currentNode) {
            return currentNode.getId();
        }

        @Override
        public <P extends CommonTreeEntity> void init(Long userId, P currentNode, P node) {
            node.setParentId(currentNode.getId());
            node.setLevel(currentNode.getLevel() + 1);
            node.setOrder(0);
        }
    };


    NodeAppendOperation() {

    }

    /**
     * 选出条件ID
     *
     * @param <P>         the type parameter
     * @param currentNode the current node
     * @return the reset order condition
     */
    abstract <P extends CommonTreeEntity> Long dedicate(P currentNode);

    /**
     * Init.
     *
     * @param <P>         the type parameter
     * @param userId      the user id
     * @param currentNode the current node
     * @param node        the node
     */
    public abstract <P extends CommonTreeEntity> void init(Long userId, P currentNode, P node);

}
